home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr52 / expand53.zip / XPNGDEMO.ZIP / NGVIEW.PRG < prev   
Text File  |  1992-08-21  |  7KB  |  300 lines

  1. * ------------------------------------------------------------------------
  2. * File........:    NGVIEW.PRG
  3. * Author......:    Pepijn Smits
  4. * Copyright...:    (c)1992, by "Softwarebureau Pepijn Smits", Rotterdam.
  5. * Date........:    August 1992
  6. * Compiler....:    Clipper 5.01, Compile with /m /l /n /v
  7. * Notes.......:    Norton Guides Viewer: Demonstrates the use of the
  8. *        Expand Library.
  9. *
  10. * Please note also that the program isn't quite ready yet. It's a good
  11. * demo of what is possible with the NG routines, The demo itself is not
  12. * very well behaved. Some ShortCuts, for instance, do not work as expected.
  13. * Feel free to adapt the Demo where necessary, it's intended as a Demo and
  14. * not much more.
  15. * ------------------------------------------------------------------------
  16. #include     "INKEY.CH"
  17.  
  18. #xcommand    MenuColor()    =>    setColor(if(IsColor(),"N/W,W+/R,,R/W,GR+/R","W/N,N/W,,W+/N,N/W")) ;
  19.                     ; XPcolor()
  20.  
  21. #xcommand    NormColor()    =>    setColor(if(isColor(),"BG+/B,N/BG,,GR+/B,W+/BG","N/W,W/N,,N/W,W+/N")) ;
  22.                     ; XPcolor()
  23.  
  24. Static M := {    {'≡',    {'~A~bout..',;
  25.                 'Display some version information',;
  26.                     {||About()} },;
  27.             {'~H~elp         ~F1~',;
  28.                 'Display Help for this program',;
  29.                     {||Help()} },;
  30.             {'~C~redits      ~F3~',;
  31.                 'Display database credits',;
  32.                     {||Credits()} },;
  33.             {'E~x~it      ~Alt-X~',;
  34.                 'Quit the program',;
  35.                     {||Stop()} } } }
  36.  
  37. Procedure Main()
  38. Local i,j,n
  39. Local cFile := Upper(AllTrim(XPcommandLine()))
  40. if At('.',cFile)==0
  41.     cFile+=".NG"
  42. end
  43. if Empty(cFile)
  44.     ?? 'Norton Guides Viewer v1.00, Written by Pepijn Smits, 1992.'
  45.     ?
  46.     ? 'Usage: NGview <NortonGuideDatabase>'
  47.     ?
  48.     quit
  49. end
  50. if NGopen(cFile)
  51.     MenuColor()
  52.     DispBox(0,0,maxRow(),MaxCol(),"░░░░░░░░░")
  53.     if NGmenus() > 0
  54.         for i := 1 to NGmenus()
  55.             aAdd(m,{NGmenuTitle(i)})
  56.             for j := 1 to NGmenuCount(i)
  57.                 aAdd(m[i+1],;
  58.                     { NGmenuLabel(i,j),;
  59.                      NGname() +' » '+ NGmenuTitle(i) + ' » ' +NGmenuLabel(i,j),;
  60.                      {||HandleMenu()} })
  61.             next
  62.         next
  63.     else
  64.         aAdd(m,{NGname(),{NGname(),NGname()+' » (No menu entries)',{||HandleMenu()}}})
  65.     end
  66.     XPpullInit(m,{|cMsg|HandleMsg(cMsg)})
  67.     While .t.
  68.         Eval(XPpullMenu())
  69.     end
  70. else
  71.     ?? 'Norton Guides Viewer v1.00, Written by Pepijn Smits, 1992.'
  72.     ?
  73.     ? 'Error: File not Found or not a valid Norton Guide: '+cFile
  74.     ?
  75. end
  76. quit
  77. Return
  78.  
  79. Function HandleMsg(cMsg)
  80. XPmsg(PadR(" "+cMsg,69)+" ~│~ NGview")
  81. Return (NIL)
  82.  
  83. Function Stop()
  84. setColor('')
  85. cls
  86. quit
  87. Return (NIL)
  88.  
  89. Function About()
  90. Local c := SetColor()
  91. MenuColor()
  92. XPalert('About ~NGview~',;
  93.     ';This program is written in ~Clipper 5.01~;'+;
  94.     'using the ~Expand Library v3.00~ which contains routines;'+;
  95.     'to read and interpret ~Norton Guides~.;;'+;
  96.     'Copyright (c) 1992, Written by Pepijn Smits')
  97. SetColor(c)
  98. XPcolor()
  99. Return (NIL)
  100.  
  101. Function Help()
  102. Local c := SetColor()
  103. MenuColor()
  104. XPalert("Help for ~NGview~",;
  105.     ';~Esc~      Back-Up one Level (does not quit Application though) '+;
  106.     ';~Enter~    Select the currently High-lighted item               '+;
  107.     ';~Cursor~   Move the selection Bar, dos scroll in text entries   '+;
  108.     ';~F2~       Display the List of Related Topics (in text entries) '+;
  109.     ';~F3~       Display the Database credits                         '+;
  110.     ';~F10~      Go directly to the menu options (from any entry)     '+;
  111.     ';~+~        Go to the next text entry (only in text entries)     '+;
  112.     ';~-~        Go to the previous text entry (only in text entries) '+;
  113.     ';~Alt-X~    Quit the Application at once                         ')
  114. SetColor(c)
  115. XPcolor()
  116. Return (NIL)
  117.  
  118. Function Credits()
  119. Local c := SetColor()
  120. Local s := ""
  121. MenuColor()
  122. aEval(NGcredit(),{|l|s+=PadR(l,66)+';'})
  123. XPalert("Database credits",;
  124.     ";Current database: ~"+NGname()+"~;;"+s)
  125. SetColor(c)
  126. XPcolor()
  127. Return (NIL)
  128.  
  129. Function Info()
  130. /**
  131. * "Non Documented", Alt-I displays some Guide Entry information
  132. */
  133. Local c := SetColor()
  134. MenuColor()
  135. XPalert("Guide ~Info~",;
  136.     ";Info about the current Entry:;"+;
  137.     ";NGnext          : ~"+Str(NGnext(),8) +;
  138.     ";NGprev          : ~"+Str(NGprev(),8) +;
  139.     ";NGmenuParent[1] : ~"+Str(NGmenuParent()[1],8)+;
  140.     ";NGmenuParent[2] : ~"+Str(NGmenuParent()[2],8)+;
  141.     ";NGparent[1]     : ~"+Str(NGparent()[1],8)+;
  142.     ";NGparent[2]     : ~"+Str(NGparent()[2],8) )
  143. SetColor(c)
  144. XPcolor()
  145. Return (NIL)
  146.  
  147. Function HandleTitle()
  148. Local i := NGmenuParent()[1]
  149. Local j := NGmenuParent()[2]
  150. Local s :=    NGname()+' » ' +;
  151.         NGmenuTitle(i)+;
  152.         ' » '+;
  153.         NGmenuLabel(i,j)
  154. if NGparent()[1] <> -1
  155.     s+=" » .."
  156. end
  157. XPdisplay(1,1,replicate('═',MaxCol()-1))
  158. XPcenter(1,' '+s+' ')
  159. Return (NIL)
  160.  
  161. Function HandleMenu()
  162. Local i := XPcurrentX()-1        // Get Current Menu, which is Menu's X-1
  163. Local j := XPcurrentY()            // Get Current Menu Entry, which is Y
  164.                     // Get Entry (is 378 when No menus)
  165. Local e := if(NGmenus()>0,NGmenuEntry(i,j),378)
  166. Local n := 1
  167. Local c := SetColor()
  168. NormColor()
  169. While e <> -1
  170.     NGmsg(" Loading Entry, please wait..")
  171.     Scroll(1,0,MaxRow()-1,MaxCol(),0)
  172.     DispBox(1,0,MaxRow()-1,MaxCol(),2)
  173.     e := HandleEntry(e,@n)
  174. end
  175. XPcurrentX( NGmenuParent()[1]+1 )
  176. XPcurrentY( NGmenuParent()[2] )
  177. SetColor(c)
  178. XPcolor()
  179. Return (NIL)
  180.  
  181. Function HandleEntry(e,n)
  182. Local x := NGtype(e)
  183. Local nEntry := e
  184. Local a,s,i
  185. if x = 0
  186.     a := NGshort(e)
  187.     HandleTitle()
  188.     NGmsg(" ~F1~-Help,  ~F3~-Credits  ~F10~-Back  ~Up~-~Dn~-~PgUp~-~PgDn~-~Home~-~End~-Move,  ~Alt-X~-Quit")
  189.     XPmouseChoice(2,1,MaxRow()-2,MaxCol()-1,;
  190.         {|x|if(x=0,len(a),a[x,1])},;
  191.         {|nMode,i|ShortKey(nMode,i,a,@nEntry,@n)},n+1)
  192. elseif x = 1
  193.     s := NGlong(e)
  194.     HandleTitle()
  195.     NGmsg(" ~F1~-Help,  ~F2~-See Also,  ~F3~-Credits  ~Up~-~Dn~-~PgUp~-~PgDn~-~Home~-~End~-Move,  ~Alt-X~-Quit")
  196.     XPmouseBrowse(2,1,MaxRow()-2,maxCol()-1,s,;
  197.         {|nMode|LongKey(nMode,@nEntry,@n)})
  198. end
  199. Return (nEntry)
  200.  
  201. Function ShortKey(nMode,i,a,nEntry,n)
  202. Local nKey := LastKey()
  203. n := 1
  204. do case
  205. case nKey == K_ALT_X
  206.     Stop()
  207. case nKey == K_ALT_I
  208.     Info()
  209. case nKey == K_F1
  210.     Help()
  211. case nKey == K_F3
  212.     Credits()
  213. case nKey == K_F10
  214.     nEntry := -1
  215.     nKey := K_ESC
  216. case nKey == K_ENTER
  217.     if a[i,2] <> -1
  218.         nEntry := a[i,2]
  219.     else
  220.         nKey := 32
  221.     end
  222. case nKey == K_ESC
  223.     if NGparent()[1] <> -1
  224.         nEntry := NGparent()[1]
  225.         n := NGparent()[2]
  226.     else
  227.         nEntry := -1
  228.     end
  229. endcase
  230. Return (nKey)
  231.  
  232. Function LongKey(nMode,nEntry,n)
  233. Local nKey := LastKey()
  234. do case
  235. case nKey == K_ALT_X
  236.     Stop()
  237. case nKey == K_ALT_I
  238.     info()
  239. case nKey == K_F1
  240.     Help()
  241. case nKey == K_F2
  242.     nKey := LongSeeAlso(@nEntry)
  243. case nKey == K_F3
  244.     Credits()
  245. case nKey == K_F10
  246.     nEntry := -1
  247.     nKey := K_ESC
  248. case nKey == K_ESC
  249.     nEntry := NGparent()[1]
  250.     if nEntry <> -1
  251.         n := NGparent()[2]
  252.     end
  253. case nKey == Asc('-')
  254.     if NGnext() <> -1
  255.         nEntry := NGnext()
  256.         nKey := K_ESC
  257.     end
  258. case nKey == Asc('+')
  259.     if NGprev() <> -1
  260.         nEntry := NGprev()
  261.         nKey := K_ESC
  262.     end
  263. endcase
  264. Return (nKey)
  265.  
  266. Function LongSeeAlso(nEntry)
  267. Local nKey := 0
  268. Local a := NGseeAlso(nEntry)
  269. Local aMsg := {}
  270. Local c := SetColor()
  271. Local i
  272. MenuColor()
  273. if (a == NIL)
  274.     a := {}
  275. end
  276. if len(a) == 0
  277.     XPalert('See Also',";Sorry, There are no ~See Also~ References here;")
  278. else
  279.     aEval(a,{|e|aAdd(aMsg,e[1])})
  280.     i := XPboxMenu("See Also",aMsg)
  281.     if i > 0
  282.         nEntry := a[i,2]
  283.         nKey := K_ESC
  284.     end
  285. end
  286. SetColor(c)
  287. XPcolor()
  288. Return (nKey)
  289.  
  290. Function NGmsg(s)
  291. /***
  292. * We've got to fool with the Color here..
  293. */
  294. Local c := SetColor()
  295. MenuColor()
  296. XPmsg(s)
  297. SetColor(c)
  298. XPcolor()
  299. Return (NIL)
  300.